package com.lpx.blog.config;

//import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.xxl.job.core.util.DateUtil;
import net.sf.jsqlparser.expression.DateTimeLiteralExpression;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDateTime;


/**
 * @author MCX
 * @description
 * @date 2023-06-13
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		/* 创建时间 */
		this.strictInsertFill(metaObject, "gmtCreate", LocalDateTime.class, LocalDateTime.now());
		this.strictInsertFill(metaObject, "gmtModified", LocalDateTime.class, LocalDateTime.now());
		/* 操作人 */
		String loginIdString = "System";
//		try {
//			loginIdString = StpUtil.getLoginIdAsString();
//		} catch (Exception ignored) {
//		}
		this.strictInsertFill(metaObject, "createBy", String.class, loginIdString);
		this.strictInsertFill(metaObject, "updatedBy", String.class, loginIdString);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		/* 更新时间 */
		this.strictUpdateFill(metaObject, "gmtModified", LocalDateTime.class, LocalDateTime.now());
		/* 操作人 */
		String loginIdString = "System";
//		try {
//			loginIdString = StpUtil.getLoginIdAsString();
//		} catch (Exception ignored) {
//		}
		this.strictInsertFill(metaObject, "updatedBy", String.class, loginIdString);
	}
}
